/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test.services;

import java.util.Date;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import test.services.intfc.IRegService;

/**
 *
 * @author hjhi
 */
@Service("regService")
public class RegService implements IRegService {

    ApplicationContext ac = new ClassPathXmlApplicationContext("//applicationContext.xml");
    DataSource dataSource = (DataSource) ac.getBean("dataSource");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    @Override
    public int registerUser(String cn, String owner, Date regDate, String loc) {
        String query = "INSERT INTO registration(\"company_name\", \"owner\", \"registered_date\", \"location\") values(?,?,?,?)";

        Object[] parameters = new Object[]{cn,owner,regDate,loc};
        int c = jdbcTemplate.queryForInt(query, parameters);
        return c;

    }
}
